Shader "Unlit/FlowingLight"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _LightTex ("LightTex", 2D) = "white" {}
        _Speed("Speed",Float) = 1
        _UpScale("UpScale",Float) = 1
        _Color("Color",Color) = (1,1,1,1)
        _LightScale("LightScale",Float) = 0.5
    }
    SubShader
    {
        Tags
        {
            "RenderType"="Opaque"
        }
        LOD 100

        Pass
        {
            Blend SrcAlpha OneMinusSrcAlpha
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_fog
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            
            sampler2D _LightTex;
            float4 _LightTex_ST;
            
            float _Speed;
            float _UpScale;
            float4 _Color;
            float _LightScale;

            v2f vert(appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                return o;
            }

            fixed4 frag(v2f i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.uv);
                half2 uv = i.uv;
                uv.x += _Time.y * _Speed;
                fixed4 col2 = tex2D(_LightTex, uv);
                //如果底图是透明的，则不显示当前采样的流光颜色
                fixed4 col3 = col + col.a * col2;
                return col3;
            }
            ENDCG
        }
    }
}